package com.cskaoyan.catmall.controller.background;

import com.cskaoyan.catmall.dao.AfterSaleDao;
import com.cskaoyan.catmall.model.bo.AfterSaleBatchBo;
import com.cskaoyan.catmall.model.bo.AfterSaleBo;
import com.cskaoyan.catmall.model.bo.AfterSaleOrderInfoBo;
import com.cskaoyan.catmall.model.vo.AfterSaleVo;
import com.cskaoyan.catmall.model.vo.BaseRespVo;
import com.cskaoyan.catmall.service.AfterSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: 逍遥子
 * @Date: 2022/01/07/21:21
 * @Description:
 */
@RestController
@RequestMapping("/admin/aftersale")
public class AfterSaleController {

    @Autowired
    AfterSaleService afterSaleService;

    /**
     * @description 售后订单列表
     * @author czx
     * @date 2022-01-08 9:09
     * @param
     * @param afterSaleBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     */
    @GetMapping("list")
    public BaseRespVo list(AfterSaleBo afterSaleBo){
        AfterSaleVo afterSaleVo = afterSaleService.selectAfterSale(afterSaleBo);

        return BaseRespVo.ok(afterSaleVo);

    }

    /**
     * @description 批量通过售后订单申请
     * @author czx
     * @date 2022-01-08 9:10
     * @param
     * @param afterSaleBatchBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     */

    @PostMapping("batch-recept")
    public BaseRespVo  batchRecept(@RequestBody AfterSaleBatchBo afterSaleBatchBo){
        int res = afterSaleService.updateAfterSale(afterSaleBatchBo.getIds(), 2);
        if(res == 1){
           return BaseRespVo.ok();
        }else{
            return BaseRespVo.fail();
        }
    }

    /**
     * @description 批量拒绝售后订单申请
     * @author czx
     * @date 2022-01-08 9:10
     * @param
     * @param afterSaleBatchBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     */
    @PostMapping("batch-reject")
    public BaseRespVo batchReject(@RequestBody AfterSaleBatchBo afterSaleBatchBo){
        int res = afterSaleService.updateAfterSale(afterSaleBatchBo.getIds(), 4);
        if(res == 1){
            return BaseRespVo.ok();
        }else{
            return BaseRespVo.fail();
        }
    }

    /**
     * @description 处理退款订单
     * @author czx
     * @date 2022-01-08 9:11
     * @param
     * @param afterSaleOrderInfoBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     */
    @PostMapping("refund")
    public BaseRespVo refund(@RequestBody AfterSaleOrderInfoBo afterSaleOrderInfoBo){
        int res = afterSaleService.updateAfterSaleRefundInfo(afterSaleOrderInfoBo);
        if(res == 1){
            return BaseRespVo.ok("退款成功");
        }else{
            return BaseRespVo.fail("退款失败");
        }
    }

    /**
     * @description 同意退款
     * @author czx
     * @date 2022-01-12 16:46
     * @param
     * @param null
     * @return
     */
    @PostMapping("recept")
    public BaseRespVo recept(@RequestBody AfterSaleOrderInfoBo afterSaleOrderInfoBo){

        afterSaleService.updateAfterSaleStatus(afterSaleOrderInfoBo, 2);
        return BaseRespVo.ok();


    }

    /**
     * @description 拒绝退款申请
     * @author czx
     * @date 2022-01-12 17:16
     * @param
     * @param afterSaleOrderInfoBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     */
    @PostMapping("reject")
    public BaseRespVo reject(@RequestBody AfterSaleOrderInfoBo afterSaleOrderInfoBo){

        afterSaleService.updateAfterSaleStatus(afterSaleOrderInfoBo, 4);
        return BaseRespVo.ok();

    }

}
